<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig">
			<template v-slot:compareAreaForm="{ row, model }">
				<el-checkbox-group v-model="model.compareArea">
					<el-checkbox v-for="(item, index) in areaOptions" :key="index" :label="item.administrationName" :value="`${item.id}`" />
				</el-checkbox-group>
			</template>
			<template v-slot:compareOptionsForm="{ row, model }">
				<DividerHtml modelValue="常识比对"></DividerHtml>
				<el-checkbox-group v-model="model.compareOptions">
					<el-checkbox v-for="(item, index) in optionsList(1)" :key="index" :label="item.label" :value="item.value" />
				</el-checkbox-group>
				<DividerHtml modelValue="跨区比对" class="w-100"></DividerHtml>
				<el-checkbox-group v-model="model.compareOptions">
					<el-checkbox v-for="(item, index) in optionsList(2)" :key="index" :label="item.label" :value="item.value" />
				</el-checkbox-group>
			</template>
			<template v-slot:detailDialog="{ show, row }">
				<Detail :compareRuleId="row.id" v-if="show" :areaOptions="areaOptions"></Detail>
			</template>
		</aplid-base-crud>
	</BaseContainer>
</template>

<script setup>
import { baseConfig } from './config'
import apiMod from '@/apiMod/index'
import { getStore } from '@/utils/store'
import Detail from './Detail/index.vue'
import DividerHtml from '@/views/aplid/DividerHtml/index.vue'
const userInfo = getStore('userInfo') || {}
const authAreaArr = [userInfo.authProvince, userInfo.authCity, userInfo.authArea, userInfo.authStreet, userInfo.authCommunity].filter(Boolean)
const areaOptions = ref([])
let dictList = {}
const optionsList = (type) => {
	if (!type) type = 1
	return type == 2 ? dictList.filter((item) => item.value >= 20) : dictList.filter((item) => item.value < 20)
}

const getInitData = () => {
	apiMod
		.sysadministration_getTree({
			administrationPid: authAreaArr[authAreaArr.length - 1] || 199554,
		})
		.then((res) => {
			areaOptions.value = res.data
		})
}

onMounted(async () => {
	try {
		const { data } = await apiMod.getDictItemList('REPOS_COMPARE_RULE')
		dictList = data['REPOS_COMPARE_RULE'] || []
		getInitData()
	} catch (error) {}
})
</script>

<style lang="scss" scoped></style>
